package com.ruoyi.demo.controller

import com.ruoyi.common.core.controller.BaseController
import com.ruoyi.common.core.domain.AjaxResult
import com.ruoyi.common.core.page.TableDataInfo
import com.ruoyi.demo.domain.dto.DemoDTO
import com.ruoyi.demo.service.IDemoService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController


/**
 * @author LikeYouDo
 * @date 2025/09/23
 */
@RestController
@RequestMapping("/system/demo")
class DemoController(
    private val demoService: IDemoService
) : BaseController() {

    /**
     * 分页条件查询
     */
    @GetMapping("/list")
    fun list(dto: DemoDTO): TableDataInfo {
        return getDataTable(demoService.listDemo(dto))
    }

    /**
     * kotlin构建复杂查询
     */
    @GetMapping("/query")
    fun queryByCondition(dto: DemoDTO): AjaxResult {
        return AjaxResult.success(demoService.queryByCondition(dto))
    }

    /**
     * 根据id查询
     */
    @GetMapping("/get/{id}")
    fun get(@PathVariable id: Long): AjaxResult {
        return AjaxResult.success(demoService.getById(id))
    }

    /**
     * 新增
     */
    @PostMapping("/addDemo")
    fun addDemo(dto: DemoDTO): AjaxResult{
        return toAjax(demoService.addDemo(dto))
    }
}